from multiprocessing import Manager, Pool
from time import sleep


def write(q):
    name = ["a", "b", "I am congyu", 500]
    for item in name:
        if not q.full():
            print(f"开始写入：{item}")
            q.put(item)
            sleep(1)
    print(f"写入结束,现有元素总数: {q.qsize()}")


def reader(q):
    for item in range(q.qsize()):
        print(f"读取第{item}值： {q.get()}")
        sleep(1)
    print(f"读取结束,现有元素总数: {q.qsize()}")


if __name__ == "__main__":
    queue = Manager().Queue()
    pool = Pool(3)
    pool.apply(write, (queue,))
    pool.apply(reader, (queue,))

    pool.close()
    pool.join()
